<?php

    // Include domain-specific classes
    require dirname(__FILE__) . DIRECTORY_SEPARATOR . '_include.php';
    
    try {
        
        //----------------------------------------------------------------------
        // Initialise domain objects
        
        // The Master Datagateway will be the base object to amend functionality.
        
        $obj_datagateway = new DataGateway_Master();
        
        // The Cache Datagateway will be the extra functionality to combine with
        // the base object.
        
        $obj_datagateway_cache = new DataGateway_Cache();
    
        
        //----------------------------------------------------------------------
        // Create weaved delegator
        
        // Encapsulate the base object within a Weaved Delegator; this will 
        // provide the means to add functionality after a method is invoked.
        
        $obj = new ClassStructure_Weaved_Delegator($obj_datagateway);
        
        // Define a "pointcut" which will be used to match methods in which to
        // weave functionality.
        
        $obj_pointcut = new ClassStructure_PointCut();
        $obj_pointcut->setPattern('/insert.*/');
        
        // Instruct the Weaved Delegator to invoke the clearCache() method 
        // after the base object has invoked any method that reflects the pointcut.
        
        $obj->__weaveAdviceAfter(
            array($obj_datagateway_cache, 'clearCache'), 
            $obj_pointcut
        );
        
        //----------------------------------------------------------------------
        // Test functionality
        
        $obj->insertPressTitle(array(
            'title_name' => 'Financial Times',
            'title_slug' => 'financial-times',
            'title_type' => 'newspaper',
            'categories' => array(1)
        ));
        
        echo "\n\n";
        
        //----------------------------------------------------------------------
        // Expose structure
        
        echo ClassStructure_UtilityFunctions::getObjectSignature($obj);
        echo "\n";
        echo ClassStructure_UtilityFunctions::getAdviceSignature($obj, 'insertPressTitle');
        
    } catch (Exception $obj_exception) {
        print_r($obj_exception);
    }
